package com.family.controller;

import com.family.domain.Book;
import com.family.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private BookService bookService;

    @PostMapping//http://localhost:8888/books
    public boolean save(@RequestBody Book book) {//{"type":"test0","name":"test0","description":"test0"}
        return bookService.save(book);
    }

    @PutMapping
    public boolean update(@RequestBody Book book) {//{"id":13,"type":"test999","name":"test999","description":"test999"}
        return bookService.update(book);
    }

    @DeleteMapping("/{id}")//http://localhost:8888/books/14
    public boolean delete(@PathVariable Integer id) {
        return bookService.delete(id);
    }

    @GetMapping("/{id}")//http://localhost:8888/books/13
    public Book getById(@PathVariable Integer id) {
        return bookService.getById(id);
    }

    @GetMapping
    public List<Book> getAll() {
        return bookService.getAll();
    }
}
